package HW5;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args)  {
        ServerSocket ss = null;
        Socket s = null;


        try {
            //建立socket 链接
           ss = new ServerSocket(8080);

           while(true){
               System.out.println("等待链接中...");
               //监听
               s = ss.accept();
               System.out.println(s.getInetAddress().getHostName() + "链接成功");
               new MutliThread(s).start();
           }

        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            if(null!=ss){
                try {
                    ss.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(null!=s){
                try {
                    s.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}
